package com.atty.dms.controller;

import com.atty.dms.common.convention.result.Result;
import com.atty.dms.common.convention.result.Results;
import com.atty.dms.dao.entity.PreferenceDO;
import com.atty.dms.dto.req.PreferenceCreateReqDTO;
import com.atty.dms.dto.req.PreferenceUpdateReqDTO;
import com.atty.dms.dto.resp.PreferenceRespDTO;
import com.atty.dms.service.PreferenceService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: PreferenceController
 * Package: com.atty.dms.controller
 * Description:
 *
 * @Author: tony
 * @Create : 2025/4/19 16:06
 * @Version : 1.0
 */
@RestController
@RequiredArgsConstructor
public class PreferenceController {

    private final PreferenceService preferenceService;

    /**
     * 根据用户ID获取偏好信息
     */
    @GetMapping("/api/dms/admin/preference/{userId}")
    public Result<PreferenceRespDTO> getPreferenceByUserId(@PathVariable("userId") Long userId) {
        return Results.success(preferenceService.getPreferenceByUserId(userId));
    }
    /**
     * 根据用户名获取偏好信息
     */
    @GetMapping("/api/dms/admin/preference/username/{username}")
    public Result<PreferenceRespDTO> getPreferenceByUserId(@PathVariable("username") String username) {
        return Results.success(preferenceService.getPreferenceByUsername(username));
    }

    /**
     * 创建偏好信息
     */
    @PostMapping("/api/dms/admin/preference")
    public Result<Void> createPreference(@RequestBody PreferenceCreateReqDTO requestParam) {
        preferenceService.createPreference(requestParam);
        return Results.success();
    }

    /**
     * 更新偏好信息
     */
    @PutMapping("/api/dms/admin/preference/{userId}")
    public Result<Void> updatePreference(@PathVariable("userId") Long userId,
                                         @RequestBody PreferenceUpdateReqDTO requestParam) {
        preferenceService.updatePreference(userId, requestParam);
        return Results.success();
    }

    /**
     * 删除偏好信息
     */
    @DeleteMapping("/api/dms/admin/preference/{userId}")
    public Result<Void> deletePreference(@PathVariable("userId") Long userId) {
        preferenceService.deletePreference(userId);
        return Results.success();
    }

    /**
     *分页查询偏好信息
     */
    @GetMapping("/api/dms/admin/preference/page")
    public Result<Page<PreferenceRespDTO>> getAllPreferenceByPage(
            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") int PageSize) {
        return Results.success(preferenceService.getAllPreferenceByPage(pageNum,PageSize));
    }

}